package com.bi.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 数据组件实体类
 * 
 * @author BI Platform Team
 * @since 1.0.0
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("tb_data_component")
public class DataComponent implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 组件名称
     */
    private String name;

    /**
     * 组件显示名称
     */
    private String displayName;

    /**
     * 组件描述
     */
    private String description;

    /**
     * 组件类型
     */
    private ComponentType type;

    /**
     * 数据源类型
     */
    private DataSourceType dataSourceType;

    /**
     * 数据源配置
     */
    private String dataSourceConfig;

    /**
     * 宽表ID(如果数据源是宽表)
     */
    private Long wideTableId;

    /**
     * SQL查询语句
     */
    private String sqlQuery;

    /**
     * ES查询配置
     */
    private String esQuery;

    /**
     * 接口配置
     */
    private String apiConfig;

    /**
     * 字段映射配置
     */
    private String fieldMapping;

    /**
     * 缓存配置
     */
    private String cacheConfig;

    /**
     * 刷新周期(分钟)
     */
    private Integer refreshInterval;

    /**
     * 状态
     */
    private ComponentStatus status;

    /**
     * 创建人
     */
    private String creator;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /**
     * 更新人
     */
    private String updater;

    /**
     * 更新时间
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    /**
     * 版本号
     */
    @Version
    private Integer version;

    /**
     * 组件类型枚举
     */
    public enum ComponentType {
        TABLE("表格组件"),
        LIST("列表组件"),
        CARD("卡片组件"),
        TREE("树形组件"),
        FORM("表单组件"),
        DETAIL("详情组件"),
        SEARCH("搜索组件"),
        FILTER("过滤组件");

        private final String description;

        ComponentType(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    /**
     * 数据源类型枚举
     */
    public enum DataSourceType {
        WIDE_TABLE("数据宽表"),
        DATABASE("数据库"),
        ELASTICSEARCH("Elasticsearch"),
        API("REST API"),
        FILE("文件数据源");

        private final String description;

        DataSourceType(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    /**
     * 组件状态枚举
     */
    public enum ComponentStatus {
        DRAFT("草稿"),
        ACTIVE("启用"),
        INACTIVE("停用"),
        DELETED("已删除");

        private final String description;

        ComponentStatus(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }
}